package com.rul.mars.order.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.rul.mars.mbg.domain.CommentReplayParam;
import com.rul.mars.mbg.mapper.CommentMapper;
import com.rul.mars.mbg.mapper.CommentReplayMapper;
import com.rul.mars.mbg.model.Comment;
import com.rul.mars.mbg.model.CommentReplay;
import com.rul.mars.mbg.model.User;
import com.rul.mars.order.service.CommentReplayService;
import com.rul.mars.order.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * 回复评论服务实现
 *
 * @author RuL
 */
@Service
public class CommentReplayServiceImpl implements CommentReplayService {

    @Autowired
    private CommentReplayMapper commentReplayMapper;
    @Autowired
    private CommentMapper commentMapper;
    @Autowired
    private UserService userService;

    @Override
    public boolean replay(CommentReplayParam param) {
        Comment comment = commentMapper.selectByPrimaryKey(param.getCommentId());
        CommentReplay commentReplay = BeanUtil.copyProperties(param, CommentReplay.class);
        //回复人信息
        User user = userService.currentUser();
        //设置回复人信息
        commentReplay.setUserId(user.getId());
        commentReplay.setUserNickName(user.getNickName());
        commentReplay.setUserIcon(user.getIcon());
        int rows = commentReplayMapper.insertSelective(commentReplay);

        //增加评论回复数
        comment.setReplayCount(comment.getReplayCount() + 1);
        return rows == 1;
    }
}
